const Koa = require("koa")
const cors = require("koa2-cors")
const logger = require("koa-logger")
const bodyParser = require("koa-body")

const router = require("./routes")
const db = require("./models")

const app = new Koa()

app.use(cors())
    .use(logger())
    .use(bodyParser())
    .use(router.routes(), router.allowedMethods())

app.listen(8888, () => {
    db.sequelize
        // 链接数据库
        .sync({ force: false, logging: false })
        .then(() => {
            console.log("sequelize connect success")
            console.log("sever listen on http://127.0.0.1:8888")
        })
        .catch(err => {
            console.log(err)
        })
})
